<template>
  <div class="wrapper">
    <swiper ref="mySwiper" :options="swiperOptions" v-if="showSwiper">
      <swiper-slide v-for="item of list" :key="item.id">
        <img :src="item.imgUrl" :alt="item.id" class="wrapper__img" />
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: "HomeSwiper",
  props: {
    list: Array,
  },
  data() {
    return {
      swiperOptions: {
        // 轮播图的小圆点
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
        // 支持循环轮播
        loop: true,
      },
    };
  },
  computed: {
    showSwiper() {
      return this.list.length;
    },
  },
};
</script>

<style lang="scss" scoped>
// scss样式穿透
.wrapper ::v-deep .swiper-pagination-bullet-active {
  background-color: #fff;
}
.wrapper {
  width: 100%;
  overflow: hidden;
  height: 0;
  // 图片的高宽比
  // 不能写成 height: 38%; 因为这样写是代表着相当于 .wrapper 的 38%
  // 也可以写成 height: 38vw; 但是这样写有些浏览器不兼容
  padding-bottom: 31.25%;
  &__img {
    width: 100%;
  }
}
</style>